package org.zoomdev.android.nfccard.cpu;

import com.zoomdev.android.hex.HexUtil;

import org.zoomdev.android.nfc.adapters.ApduException;
import org.zoomdev.android.nfc.adapters.ApduResponse;
import org.zoomdev.android.nfc.adapters.IsoDepTagAdapter;

import java.io.IOException;

public class Utils {
    static String[] send(IsoDepTagAdapter adapter,String[] commands) throws IOException, ApduException {
        if(!adapter.isConnected()){
            adapter.connect();
        }
        String[] result = new String[commands.length];
        int index=  0;
        for(String command : commands){
            ApduResponse response = adapter.apdu(HexUtil.decodeHex(command));
            result[index++] = response.getStr();
        }
        return result;
    }
    static ApduResponse send(IsoDepTagAdapter adapter,String command) throws IOException, ApduException {
       return send(adapter, HexUtil.decodeHex(command));
    }
    static ApduResponse send(IsoDepTagAdapter adapter,byte[] command) throws IOException, ApduException {
        if(!adapter.isConnected()){
            adapter.connect();
        }
        return adapter.apdu(command);
    }
}
